<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of quiverc</title>
  <meta name="keywords" content="quiverc">
  <meta name="description" content="Modified version of Quiver to plots velocity vectors as arrows">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html VMT_4.0_dev --><!-- menu.html utils -->
<h1>quiverc
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Modified version of Quiver to plots velocity vectors as arrows</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function hh = quiverc(varargin) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Modified version of Quiver to plots velocity vectors as arrows 
 with components (u,v) at the points (x,y) using the current colormap</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="cptcmap.html" class="code" title="function varargout = cptcmap(varargin)">cptcmap</a>	CPTCMAP Apply a .cpt file as colormap to an axis</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001  <a name="_sub0" href="#_subfunctions" class="code">function hh = quiverc(varargin)</a>
0002 <span class="comment">% Modified version of Quiver to plots velocity vectors as arrows</span>
0003 <span class="comment">% with components (u,v) at the points (x,y) using the current colormap</span>
0004 
0005 <span class="comment">% Bertrand Dano 3-3-03</span>
0006 <span class="comment">% Copyright 1984-2002 The MathWorks, Inc.</span>
0007 
0008 <span class="comment">%QUIVERC Quiver color plot.</span>
0009 <span class="comment">%   QUIVERC(X,Y,U,V) plots velocity vectors as arrows with components (u,v)</span>
0010 <span class="comment">%   at the points (x,y).  The matrices X,Y,U,V must all be the same size</span>
0011 <span class="comment">%   and contain corresponding position and velocity components (X and Y</span>
0012 <span class="comment">%   can also be vectors to specify a uniform grid).  QUIVER automatically</span>
0013 <span class="comment">%   scales the arrows to fit within the grid.</span>
0014 <span class="comment">%</span>
0015 <span class="comment">%   QUIVERC(U,V) plots velocity vectors at equally spaced points in</span>
0016 <span class="comment">%   the x-y plane.</span>
0017 <span class="comment">%</span>
0018 <span class="comment">%   QUIVERC(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the</span>
0019 <span class="comment">%   arrows to fit within the grid and then stretches them by S.  Use</span>
0020 <span class="comment">%   S=0 to plot the arrows without the automatic scaling.</span>
0021 <span class="comment">%</span>
0022 <span class="comment">%   QUIVERC(...,LINESPEC) uses the plot linestyle specified for</span>
0023 <span class="comment">%   the velocity vectors.  Any marker in LINESPEC is drawn at the base</span>
0024 <span class="comment">%   instead of an arrow on the tip.  Use a marker of '.' to specify</span>
0025 <span class="comment">%   no marker at all.  See PLOT for other possibilities.</span>
0026 <span class="comment">%</span>
0027 <span class="comment">%   QUIVERC(...,'filled') fills any markers specified.</span>
0028 <span class="comment">%</span>
0029 <span class="comment">%   H = QUIVERC(...) returns a vector of line handles.</span>
0030 <span class="comment">%</span>
0031 <span class="comment">%   Example:</span>
0032 <span class="comment">%      [x,y] = meshgrid(-2:.2:2,-1:.15:1);</span>
0033 <span class="comment">%      z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15);</span>
0034 <span class="comment">%      contour(x,y,z), hold on</span>
0035 <span class="comment">%      quiverc(x,y,px,py), hold off, axis image</span>
0036 <span class="comment">%</span>
0037 <span class="comment">%   See also FEATHER, QUIVER3, PLOT.</span>
0038 <span class="comment">%   Clay M. Thompson 3-3-94</span>
0039 <span class="comment">%   Copyright 1984-2002 The MathWorks, Inc.</span>
0040 <span class="comment">%   $Revision: 5.21 $  $Date: 2002/06/05 20:05:16 $</span>
0041 <span class="comment">%-------------------------------------------------------------</span>
0042 
0043 <span class="comment">% set(gca, 'color', 'blue');</span>
0044 <span class="comment">% Arrow head parameters</span>
0045 alpha = 0.33; <span class="comment">% Size of arrow head relative to the length of the vector</span>
0046 beta = 0.23;  <span class="comment">% Width of the base of the arrow head relative to the length</span>
0047 autoscale = 1; <span class="comment">% Autoscale if ~= 0 then scale by this.</span>
0048 plotarrows = 1; <span class="comment">% Plot arrows</span>
0049 sym = <span class="string">''</span>;
0050 
0051 <span class="comment">% Setup a custom colormap</span>
0052 <span class="comment">% quiverc fights for some reason if colormaps are longer than the standard</span>
0053 <span class="comment">% 64 elements. Must first ensure that the custom CPT cmap is interpolated</span>
0054 <span class="comment">% to 64 levels.</span>
0055 <span class="keyword">if</span> 0
0056     CC    = <a href="cptcmap.html" class="code" title="function varargout = cptcmap(varargin)">cptcmap</a>(<span class="string">'Primary_1.cpt'</span>); <span class="comment">% FEX in the utils folder</span>
0057 <span class="keyword">else</span>
0058     colormap jet
0059     CC = colormap;
0060 <span class="keyword">end</span>
0061 c1    = CC(:,1); c2 = CC(:,2); c3 = CC(:,3);
0062 CCx   = (1:size(CC,1))';
0063 clevs = linspace(1,size(CC,1),64)'; clevs(end) = size(CC,1);
0064 cc1   = interp1(CCx,c1,clevs);
0065 cc2   = interp1(CCx,c2,clevs);
0066 cc3   = interp1(CCx,c3,clevs);
0067 colormap([cc1 cc2 cc3]);
0068 
0069 filled = 0;
0070 ls = <span class="string">'-'</span>;
0071 ms = <span class="string">''</span>;
0072 col = <span class="string">''</span>;
0073 lw=1;
0074 
0075 nin = nargin;
0076 <span class="comment">% Parse the string inputs</span>
0077 <span class="keyword">while</span> isstr(varargin{nin}),
0078   vv = varargin{nin};
0079   <span class="keyword">if</span> ~isempty(vv) &amp; strcmp(lower(vv(1)),<span class="string">'f'</span>)
0080     filled = 1;
0081     nin = nin-1;
0082   <span class="keyword">else</span>
0083     [l,c,m,msg] = colstyle(vv);
0084     <span class="keyword">if</span> ~isempty(msg), 
0085       error(sprintf(<span class="string">'Unknown option &quot;%s&quot;.'</span>,vv));
0086     <span class="keyword">end</span>
0087     <span class="keyword">if</span> ~isempty(l), ls = l; <span class="keyword">end</span>
0088     <span class="keyword">if</span> ~isempty(c), col = c; <span class="keyword">end</span>
0089     <span class="keyword">if</span> ~isempty(m), ms = m; plotarrows = 0; <span class="keyword">end</span>
0090     <span class="keyword">if</span> isequal(m,<span class="string">'.'</span>), ms = <span class="string">''</span>; <span class="keyword">end</span> <span class="comment">% Don't plot '.'</span>
0091     nin = nin-1;
0092   <span class="keyword">end</span>
0093 <span class="keyword">end</span>
0094 
0095 
0096 error(nargchk(2,5,nin));
0097 
0098 <span class="comment">% Check numeric input arguments</span>
0099 <span class="keyword">if</span> nin&lt;4, <span class="comment">% quiver(u,v) or quiver(u,v,s)</span>
0100   [msg,x,y,u,v] = xyzchk(varargin{1:2});
0101 <span class="keyword">else</span>
0102   [msg,x,y,u,v] = xyzchk(varargin{1:4});
0103 <span class="keyword">end</span>
0104 <span class="keyword">if</span> ~isempty(msg), error(msg); <span class="keyword">end</span>
0105 
0106 <span class="keyword">if</span> nin==3 | nin==5, <span class="comment">% quiver(u,v,s) or quiver(x,y,u,v,s)</span>
0107   autoscale = varargin{nin};
0108 <span class="keyword">end</span>
0109 
0110 <span class="comment">% Scalar expand u,v</span>
0111 <span class="keyword">if</span> prod(size(u))==1, u = u(ones(size(x))); <span class="keyword">end</span>
0112 <span class="keyword">if</span> prod(size(v))==1, v = v(ones(size(u))); <span class="keyword">end</span>
0113 
0114 <span class="keyword">if</span> autoscale,
0115   <span class="comment">% Base autoscale value on average spacing in the x and y</span>
0116   <span class="comment">% directions.  Estimate number of points in each direction as</span>
0117   <span class="comment">% either the size of the input arrays or the effective square</span>
0118   <span class="comment">% spacing if x and y are vectors.</span>
0119   <span class="keyword">if</span> min(size(x))==1, n=sqrt(prod(size(x))); m=n; <span class="keyword">else</span> [m,n]=size(x); <span class="keyword">end</span>
0120   delx = diff([min(x(:)) max(x(:))])/n;
0121   dely = diff([min(y(:)) max(y(:))])/m;
0122   len = sqrt((u.^2 + v.^2)/(delx.^2 + dely.^2));
0123   autoscale = autoscale*0.9 / max(len(:));
0124   u = u*autoscale; v = v*autoscale;
0125 <span class="keyword">end</span>
0126 
0127 <span class="comment">%----------------------------------------------</span>
0128 <span class="comment">% Define colormap</span>
0129 vr=sqrt(u.^2+v.^2);
0130 vrn=round(vr/max(vr(:))*64);
0131 CC=colormap;
0132 ax = newplot;
0133 next = lower(get(ax,<span class="string">'NextPlot'</span>));
0134 hold_state = ishold;
0135 
0136 <span class="comment">%----------------------------------------------</span>
0137 <span class="comment">% Make velocity vectors and plot them</span>
0138 
0139 x = x(:).';y = y(:).';
0140 u = u(:).';v = v(:).';
0141 vrn=vrn(:).';
0142 uu = [x;x+u;repmat(NaN,size(u))];
0143 vv = [y;y+v;repmat(NaN,size(u))];
0144 vrn1= [vrn;repmat(NaN,size(u));repmat(NaN,size(u))];
0145 
0146 uui=uu(:);  vvi=vv(:);  vrn1=vrn1(:); imax=size(uui);
0147 hold on
0148 
0149  <span class="keyword">for</span> i=  1:3:imax-1
0150     ii=int8(round(vrn1(i)));
0151     <span class="keyword">if</span> ii==0; ii=1; <span class="keyword">end</span>        
0152     c1= CC(ii,1);    c2= CC(ii,2);    c3= CC(ii,3);
0153     plot(uui(i:i+1),vvi(i:i+1),<span class="string">'linewidth'</span>,lw,<span class="string">'color'</span>,[c1 c2 c3]);
0154 <span class="keyword">end</span>
0155 
0156 <span class="comment">%----------------------------------------------</span>
0157 <span class="comment">% Make arrow heads and plot them</span>
0158 <span class="keyword">if</span> plotarrows,
0159  
0160   hu = [x+u-alpha*(u+beta*(v+eps));x+u; <span class="keyword">...</span>
0161         x+u-alpha*(u-beta*(v+eps));repmat(NaN,size(u))];
0162   hv = [y+v-alpha*(v-beta*(u+eps));y+v; <span class="keyword">...</span>
0163         y+v-alpha*(v+beta*(u+eps));repmat(NaN,size(v))];
0164   vrn2= [vrn;vrn;vrn;vrn];
0165 
0166  uui=hu(:);  vvi=hv(:);  vrn2=vrn2(:); imax=size(uui);
0167 
0168  <span class="keyword">for</span> i=  1:imax-1
0169     ii=int8(round(vrn2(i)));
0170     <span class="keyword">if</span> ii==0; ii=1; <span class="keyword">end</span>   
0171     c1= CC(ii,1);    c2= CC(ii,2);    c3= CC(ii,3);
0172     plot(uui(i:i+1),vvi(i:i+1),<span class="string">'linewidth'</span>,lw,<span class="string">'color'</span>,[c1 c2 c3]);
0173  <span class="keyword">end</span>
0174 
0175 <span class="keyword">else</span>
0176   h2 = [];
0177 <span class="keyword">end</span>
0178 <span class="comment">%----------------------------------------------</span>
0179 
0180 <span class="keyword">if</span> ~isempty(ms), <span class="comment">% Plot marker on base</span>
0181   hu = x; hv = y;
0182   hold on
0183   h3 = plot(hu(:),hv(:),[col ms]);
0184   <span class="keyword">if</span> filled, set(h3,<span class="string">'markerfacecolor'</span>,get(h1,<span class="string">'color'</span>)); <span class="keyword">end</span>
0185 <span class="keyword">else</span>
0186   h3 = [];
0187 <span class="keyword">end</span>
0188 
0189 <span class="keyword">if</span> ~hold_state, hold off, view(2); set(ax,<span class="string">'NextPlot'</span>,next); <span class="keyword">end</span>
0190 
0191 <span class="keyword">if</span> nargout&gt;0, hh = [h1;h2;h3]; <span class="keyword">end</span>
0192 <span class="comment">% set(gca, 'color', [0 0 0],'Xcolor','w','Ycolor','w');</span>
0193 <span class="comment">% set(gcf, 'color', [0 0 0]);</span>
0194 <span class="comment">% set(gcf, 'InvertHardCopy', 'off');</span></pre></div>
<hr><address>Generated on Thu 21-Mar-2013 09:32:01 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>